<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of gbayes</title>
  <meta name="keywords" content="gbayes">
  <meta name="description" content="GBAYES	Evaluate gradient of Bayesian error function for network.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">netlab</a> &gt; gbayes.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\netlab&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>gbayes
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>GBAYES	Evaluate gradient of Bayesian error function for network.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [g, gdata, gprior] = gbayes(net, gdata) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">GBAYES    Evaluate gradient of Bayesian error function for network.

    Description
    G = GBAYES(NET, GDATA) takes a network data structure NET together
    the data contribution to the error gradient for a set of inputs and
    targets. It returns the regularised error gradient using any zero
    mean Gaussian priors on the weights defined in NET.  In addition, if
    a MASK is defined in NET, then the entries in G that correspond to
    weights with a 0 in the mask are removed.

    [G, GDATA, GPRIOR] = GBAYES(NET, GDATA) additionally returns the data
    and prior components of the error.

    See also
    <a href="errbayes.html" class="code" title="function [e, edata, eprior] = errbayes(net, edata)">ERRBAYES</a>, <a href="glmgrad.html" class="code" title="function [g, gdata, gprior] = glmgrad(net, x, t)">GLMGRAD</a>, <a href="mlpgrad.html" class="code" title="function [g, gdata, gprior] = mlpgrad(net, x, t)">MLPGRAD</a>, <a href="rbfgrad.html" class="code" title="function [g, gdata, gprior] = rbfgrad(net, x, t)">RBFGRAD</a></pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="netpak.html" class="code" title="function w = netpak(net)">netpak</a>	NETPAK	Combines weights and biases into one weights vector.</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="glmgrad.html" class="code" title="function [g, gdata, gprior] = glmgrad(net, x, t)">glmgrad</a>	GLMGRAD Evaluate gradient of error function for generalized linear model.</li><li><a href="mlpgrad.html" class="code" title="function [g, gdata, gprior] = mlpgrad(net, x, t)">mlpgrad</a>	MLPGRAD Evaluate gradient of error function for 2-layer network.</li><li><a href="rbfgrad.html" class="code" title="function [g, gdata, gprior] = rbfgrad(net, x, t)">rbfgrad</a>	RBFGRAD Evaluate gradient of error function for RBF network.</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [g, gdata, gprior] = gbayes(net, gdata)</a>
0002 <span class="comment">%GBAYES    Evaluate gradient of Bayesian error function for network.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">%    Description</span>
0005 <span class="comment">%    G = GBAYES(NET, GDATA) takes a network data structure NET together</span>
0006 <span class="comment">%    the data contribution to the error gradient for a set of inputs and</span>
0007 <span class="comment">%    targets. It returns the regularised error gradient using any zero</span>
0008 <span class="comment">%    mean Gaussian priors on the weights defined in NET.  In addition, if</span>
0009 <span class="comment">%    a MASK is defined in NET, then the entries in G that correspond to</span>
0010 <span class="comment">%    weights with a 0 in the mask are removed.</span>
0011 <span class="comment">%</span>
0012 <span class="comment">%    [G, GDATA, GPRIOR] = GBAYES(NET, GDATA) additionally returns the data</span>
0013 <span class="comment">%    and prior components of the error.</span>
0014 <span class="comment">%</span>
0015 <span class="comment">%    See also</span>
0016 <span class="comment">%    ERRBAYES, GLMGRAD, MLPGRAD, RBFGRAD</span>
0017 <span class="comment">%</span>
0018 
0019 <span class="comment">%    Copyright (c) Ian T Nabney (1996-2001)</span>
0020 
0021 <span class="comment">% Evaluate the data contribution to the gradient.</span>
0022 <span class="keyword">if</span> (isfield(net, <span class="string">'mask'</span>))
0023    gdata = gdata(logical(net.mask));
0024 <span class="keyword">end</span>
0025 <span class="keyword">if</span> isfield(net, <span class="string">'beta'</span>)
0026   g1 = gdata*net.beta;
0027 <span class="keyword">else</span>
0028   g1 = gdata;
0029 <span class="keyword">end</span>
0030 
0031 <span class="comment">% Evaluate the prior contribution to the gradient.</span>
0032 <span class="keyword">if</span> isfield(net, <span class="string">'alpha'</span>)
0033    w = <a href="netpak.html" class="code" title="function w = netpak(net)">netpak</a>(net);
0034    <span class="keyword">if</span> size(net.alpha) == [1 1]
0035       gprior = w;
0036       g2 = net.alpha*gprior;
0037    <span class="keyword">else</span>
0038       <span class="keyword">if</span> (isfield(net, <span class="string">'mask'</span>))
0039          nindx_cols = size(net.index, 2);
0040          nmask_rows = size(find(net.mask), 1);
0041          index = reshape(net.index(logical(repmat(net.mask, <span class="keyword">...</span>
0042             1, nindx_cols))), nmask_rows, nindx_cols);
0043       <span class="keyword">else</span>
0044          index = net.index;
0045       <span class="keyword">end</span>
0046       
0047       ngroups = size(net.alpha, 1);
0048       gprior = index'.*(ones(ngroups, 1)*w);
0049       g2 = net.alpha'*gprior;
0050    <span class="keyword">end</span>
0051 <span class="keyword">else</span>
0052   gprior = 0;
0053   g2 = 0;
0054 <span class="keyword">end</span>
0055 
0056 g = g1 + g2;</pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>